package com.hh.game.service.gateway.filter.security;

import java.util.HashMap;
import java.util.Map;

public class SecurityConfig {
    Map<String , SecurityEnum> routes;
    private String loginRoute = "hall.login.login";
    private SecurityEnum defaultSecurityEnum = SecurityEnum.LOGIN;

    public boolean isLoginRoute(String route) {
        return route!= null && route.equals(loginRoute);
    }

    public SecurityEnum getSecurityEnum(String route){
        SecurityEnum securityEnum = routes.get(route);
        if(securityEnum == null){
            securityEnum = defaultSecurityEnum;
        }
        return securityEnum;
    }

    public void setLoginRoute(String loginRoute) {
        this.loginRoute = loginRoute;
    }


    public void setRoutes(Map<String, String> routes) {
        this.routes = new HashMap<>();
        routes.entrySet().forEach(entry ->
                this.routes.put(entry.getKey() ,SecurityEnum.parseVal(entry.getValue()))
        );
    }

    public void setDefault(String defaultSecurityEnum) {
        this.defaultSecurityEnum = SecurityEnum.parseVal(defaultSecurityEnum);
        if(this.defaultSecurityEnum == null){
            this.defaultSecurityEnum = SecurityEnum.LOGIN;
        }
    }
}
